<?php

namespace App\Repositories;

use App\Models\Company;
use BobCoder\Construct\Foundation\Repository\Repository;
use Illuminate\Support\Facades\DB;

class CompanyRepository extends Repository
{
    protected $model;

    public function __construct()
    {
        $this->model = new Company();
    }


    /**
     * 管理员公司列表
     * @param array $columns
     * @return array
     * @Author 姿势就是力量
     */
    public function getListByAdmin(array $columns = ['*'])
    {
        $ids = session('companyIds');
        if (!$ids) return [];
        return $this->model->select($columns)->whereIn('id', $ids)->orderBy('created_at', 'desc')->get();
    }


    /**
     * 公司业务类型
     * @param int $companyId 公司ID
     * @return mixed
     * @Author 姿势就是力量
     */
    public function getServiceType(int $companyId)
    {
        return $this->model->select(['id'])->with(['service_type:id,name'])->find($companyId);
    }

}
